//
//  PushViewController.m
//  Commerce
//
//  Created by 高飞 on 15/5/10.
//  Copyright (c) 2015年 fei. All rights reserved.
//

#import "PushViewController.h"

@interface PushViewController (){
    NSArray *_dataArray;
}

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation PushViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [_tableView setTableFooterView:[UIView new]];
    [self getData];
    // Do any additional setup after loading the view from its nib.
}

- (void)getData{
    [SVProgressHUD showWithStatus:@"加载中" maskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parameters = [GlobalData paramterDic];
    NSString *uid = [[GlobalData sharedGlobalData] userinfoDic][@"UserID"];
    [parameters addEntriesFromDictionary:@{@"userid":uid}];
    [[BaseNetwork alloc] initWithMethodUrl:[NSString stringWithFormat:@"%@/user/log",URL_ROOT]
                                    params:nil
                               requestMode:DGHTTPMethodPOST
                               loadingShow:YES
                              didFinshLoad:^(id result) {
                                  _dataArray = result;
                                  [_tableView reloadData];
                                  
                                  [SVProgressHUD dismiss];
                              }];
}

#pragma mark - Table View Delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 290, 20)];
        [label setNumberOfLines:3];
        [label setTag:1001];
        [label setFont:[UIFont systemFontOfSize:15]];
        [label setTextColor:[UIColor blackColor]];
        [cell addSubview:label];
        
        UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 290, 20)];
        [detailLabel setNumberOfLines:0];
        [detailLabel setTag:1002];
        [detailLabel setFont:[UIFont systemFontOfSize:13]];
        [detailLabel setTextColor:[UIColor blackColor]];
        [cell addSubview:detailLabel];
    }
    UILabel *label = (UILabel *)[cell viewWithTag:1001];
    UILabel *detailLabel = (UILabel *)[cell viewWithTag:1002];
    label.text = _dataArray[indexPath.row][@"Message"];
    [label sizeToFit];
    [detailLabel setFrame:CGRectMake(15, label.frame.origin.y + label.frame.size.height, 200, 20)];
    detailLabel.text = _dataArray[indexPath.row][@"Date"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
